<template>
  <view class="main">
    <u-navbar :title="tabTitle" :title-bold="true" title-color="#000"></u-navbar>
    <searchcom @searchList="searchList" :customerStr="searchData.customerStr" :countyStr="searchData.countyStr" ></searchcom>
    
      <text class="list-title"> {{ info }} - {{ title}}</text>
      <scroll-view
    :scroll-y="true"
    class="u-flex-1 of-hide"
    refresher-enabled="true"
    :refresher-triggered="triggered"
    :refresher-threshold="50"
    refresher-background="#F5F5F5"
    @refresherrefresh="onRefresh"
    @scrolltolower="onScrollToLower"
  >
 
      <view class="data-main container-body" v-for="(item, index) in dataList" :key="index">
        <view style="font-size: 34rpx;margin-bottom: 10rpx;" class="fontw">{{ item.customerName }}</view>
        <view>
          <text class="fontw"> 工程名称 ：</text>
          <text class="">
            {{ item.engineeringName }}
          </text>
        </view>
        <view style="margin: 10rpx 0;">
          <text class="fontw"> 开始时间 ：</text>
          <text class="">
            {{ item.startDate }}
          </text>
        </view>
        <view style="margin: 10rpx 0;" v-if="swiperCurrent==1">
          <text class="fontw"> 结束时间 ：</text>
          <text class="">
            {{ item.endDate }}
          </text>
        </view>
        <view>
          <text class="fontw"> 预警内容 ：</text>
          <text class="">
            {{ item.alarmContent}}
          </text>
        </view>
      </view>
    <template v-if="!showEmpty">
      <view class="c-empty p-absolute-center">
        <u-empty text="抱歉，暂无相关数据~" :src="require('@/static/image/empty.png')"></u-empty>
      </view>
    </template>
    <view class="p-t-10 p-b-10" v-else>
      <u-loadmore :status="status" />
    </view>
    </scroll-view>
 
  </view>
</template>

<script>
import searchcom from "./searchCommon.vue";
export default {
  components: { searchcom },
  data() {
    return {
        triggered:false,
        dataList:[],
      title:'',
      info:'',
      tabTitle:'',
      searchData:{
          customerNo:'',
          customerCode:'',
          pageSize: 10,
          pageNumber: 1,
        },
        swiperCurrent:0,
        type:'',
        showEmpty:true,
        status: 'loading',
    };
  },
  onLoad(options){
 
    let { title, swiperCurrent,info ,type,customerStr,customerId,countyStr} = JSON.parse(decodeURIComponent(options.item));
    this.searchData.customerStr = customerStr
    this.searchData.countyStr = countyStr
    this.searchData.customerCode= customerId
    this.title =title
    this.info =info
    this.type =type
    this.swiperCurrent =swiperCurrent
    if(this.swiperCurrent==0){
      this.tabTitle = '当前预警列表'
    }else{
      this.tabTitle = '历史预警列表'
    }
    this.getList()
  },
  methods:{
    searchList(e){
      this.searchData = Object.assign( this.searchData , e);
      this.getList()
    },
    init() {
      this.searchData.pageNumber = 1
      this.status = 'loading'
      this.showEmpty = true
    },
    onRefresh() {
      if (this.Isfreshing) return
      this.Isfreshing = true
      if (!this.triggered) {
        // 保证刷新状态下，triggered为true
        this.triggered = true
        this.init()
        this.getList()
        setTimeout(() => {
          this.triggered = false // 触发onRestore，关闭刷新图标
          this.Isfreshing = false
        }, 1200)
      }
    },
    onScrollToLower() {
      if (this.status === 'loading') {
        this.searchData.pageNumber++
        this.getList()
      }
    },
   async getList(){
    const {customerCode,pageSize,pageNumber} =this.searchData
      let url ='/excavation/alarm1/getExceedExcavationList'
      const res= await this.$get(`${url}?customerId=${customerCode}&&alarmType=${this.type}&&status=${this.swiperCurrent}&&pageSize=${pageSize}&&pageNumber=${pageNumber}`)
     
      if (res && res.body.content) {
        this.dataList = this.searchData.pageNumber === 1 ? res.body.content : this.dataList.concat(res.body.content)
        // 到底了
        if (res.body.content.length < this.searchData.pageSize) {
          this.status = 'nomore'
        }
        // 数据空
        if (this.searchData.pageNumber === 1 && this.dataList && this.dataList.length === 0) {
          this.showEmpty = false
        } else {
          this.showEmpty = true
        }
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.data-main{
    background-color: #fff;
    padding: 20rpx;
    margin-top: 20rpx;
}
.list-title{
    font-size: 32rpx;
    display: block;
    text-align: center;
    color: #f90000;
}
.list{
    height: 86vh;
}
.fontw{
  font-weight: 700;
}
</style>